/*
    Copyright 2006 Andrew Wilkinson <andrew@indiegigs.co.uk>

    This file is part of GL2x.

    GL2x is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    GL2x is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with GL2x; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef __GL2X_DRIVER_H__
#define __GL2X_DRIVER_H__

#include "gl_internal.h"

#include "texturecache/texcache.h"

#include "vertex.h"

int GL2x_main();

void flip();

void GL2x_render(struct glpoly* poly);

void GL2x_renderline(Vector v1, Vector v2, Vector c1, Vector c2);

void GL2x_driver_init();

struct GL2x_triangle_info_t {
    Vector v1;
    Vector v2;
    Vector v3;
    Vector c1;
    Vector c2;
    Vector c3;
};
typedef struct GL2x_triangle_info_t GL2x_triangle_info;

struct GL2x_triangle_pos_t {
    int x;
    int y;
    Fixed z;
    Vector colour;
};
typedef struct GL2x_triangle_pos_t GL2x_triangle_pos;

struct GL2x_triangle_delta_t {
    Fixed x_start;
    Fixed x_end;
    Fixed d1x;
    Fixed d2x;
    int dy;
    Fixed z_start;
    Fixed z_end;
    Fixed dz;
    Fixed d1z;
    Fixed d2z;
    Vector c_start;
    Vector c_end;
    Vector dc;
    Vector d1c;
    Vector d2c;
};
typedef struct GL2x_triangle_delta_t GL2x_triangle_delta;

struct GL2x_triangle_delta_flags_t {
    unsigned int x:1;
    unsigned int z:1;
    unsigned int colour:1;
};
typedef struct GL2x_triangle_delta_flags_t GL2x_triangle_delta_flags;

extern GL2x_triangle_info tri_info;
extern GL2x_triangle_delta_flags tri_flags;

// glViewport values
extern Fixed viewport_x;
extern Fixed viewport_y;
extern Fixed viewport_half_height;
extern Fixed viewport_half_width;

extern GLenum cull_face;

extern GLenum alpha_func;
extern GLclampf alpha_ref;

extern GLenum polygon_front_mode;
extern GLenum polygon_back_mode;

extern GLenum shade_model;

extern GLenum blend_func_sfactor;
extern GLenum blend_func_dfactor;

extern Fixed depth_range_near;
extern Fixed depth_range_far;

extern GLboolean depth_mask;

extern GLenum depth_func;

extern GLenum draw_buffer;
extern GLenum read_buffer;

extern GLboolean gl_alpha_test;
extern GLboolean gl_texture_1d;
extern GLboolean gl_texture_2d;
extern GLboolean gl_depth_test;

extern Fixed point_size;
extern Fixed line_width;

extern GLuint bound_tex_1d;
extern GLuint bound_tex_2d;
extern GLuint bound_tex_3d;

extern Fixed* GL2x_z_buffer;

void GL2x_renderTriangle(GL2x_triangle_info* tri_info);

void GL2x_driver_message(enum message msg, unsigned long data);

#endif

#include "shaders/shaders.h"
